/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vinavac.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Quang <quangtin3@gmail.com>
 */
@Entity
@Table(name = "commune")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Commune.findAll", query = "SELECT c FROM Commune c"),
    @NamedQuery(name = "Commune.findById", query = "SELECT c FROM Commune c WHERE c.id = :id"),
    @NamedQuery(name = "Commune.findByCommune", query = "SELECT c FROM Commune c WHERE c.commune = :commune"),
    @NamedQuery(name = "Commune.findBySite", query = "SELECT c FROM Commune c WHERE c.site = :site")})
public class Commune implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 256)
    @Column(name = "COMMUNE")
    private String commune;
    @Size(max = 32)
    @Column(name = "SITE")
    private String site;
    @ManyToMany(mappedBy = "communeList")
    private List<WeeklyCalendar> weeklyCalendarList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "commune")
    private List<Village> villageList;

    public Commune() {
    }

    public Commune(Integer id) {
        this.id = id;
    }

    public Commune(Integer id, String commune) {
        this.id = id;
        this.commune = commune;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCommune() {
        return commune;
    }

    public void setCommune(String commune) {
        this.commune = commune;
    }

    public String getSite() {
        return site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    @XmlTransient
    public List<WeeklyCalendar> getWeeklyCalendarList() {
        return weeklyCalendarList;
    }

    public void setWeeklyCalendarList(List<WeeklyCalendar> weeklyCalendarList) {
        this.weeklyCalendarList = weeklyCalendarList;
    }

    @XmlTransient
    public List<Village> getVillageList() {
        return villageList;
    }

    public void setVillageList(List<Village> villageList) {
        this.villageList = villageList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Commune)) {
            return false;
        }
        Commune other = (Commune) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getCommune() + " (" + getSite() + ")";
    }
}
